import nltk 
porter = nltk.PorterStemmer()

fr = open('../data/tagged-data/positives.txt', 'r')
fw = open('../data/stemmed-data/positives.txt', 'w')

for line in fr.readlines():
    line = line.rstrip ('\n')
    line = line.rstrip('.')
    line = [nltk.tag.str2tuple(t) for t in line.split()]
    line = [(porter.stem(word), tag) for (word, tag) in line]
    line = ' '.join([nltk.tag.tuple2str(w) for w in line])
    fw.write(line + '.' + '\n')

fr.close()
fw.close()

fr = open('../data/tagged-data/negatives.txt', 'r')
fw = open('../data/stemmed-data/negatives.txt', 'w')

for line in fr.readlines():
    line = line.rstrip ('\n')
    line = line.rstrip('.')
    line = [nltk.tag.str2tuple(t) for t in line.split()]
    line = [(porter.stem(word), tag) for (word, tag) in line]
    line = ' '.join([nltk.tag.tuple2str(w) for w in line])
    fw.write(line + '.' + '\n')

fr.close()
fw.close()
